#!/usr/bin/python3
# -*- coding:utf-8 -*-
""""
@Author: 李吉凯
@Email: lijk34925@hundsun.com
@Time: 2021/7/19 15:48
@File: dataoperation.py
"""
import os
import yaml
# from pprint import pprint


class YamlOperation:
    def __init__(self, filepath=None):
        self.filepath = filepath

    @classmethod
    def readFile(self, filepath):
        if os.path.exists(filepath):
            with open(filepath, 'r', encoding='utf-8') as f:
                content = f.read()
        else:
            content = ""
        return content

    @classmethod
    def loadYaml(self, content):
        return yaml.safe_load((content))

    @classmethod
    def readYaml(self, filepath):
        if os.path.exists(filepath):
            with open(filepath, 'r', encoding='utf-8') as f:
                cons = yaml.safe_load(f.read())
        else:
            cons = {}
        return cons

    @classmethod
    def writeYaml(self, filepath, contents):
        with open(filepath, "w", encoding="UTF-8") as f:
            yaml.dump(contents, f)
        return True

def loadYaml(content):
    return YamlOperation.loadYaml(content)

if __name__ == '__main__':
    str = """
        updatedic:
          Update_db_machine: nc19161
          Update_sqp_type: PLAT&FSK&NC
          isStop_Web: true
          upgrade_url: http://127.0.0.1:5011/act_web
          dd_url: 'https://oapi.dingtalk.com/robot/send?access_token=77da9016b0ea11e55e662d9a1775a30f314ffb79d18fa9e4ea6fd9a1a78d879e'
        """
    sss = '''
    dd_info:
        dd_tip: 缺陷已修复，请及时验证
        dd_url: https://oapi.dingtalk.com/robot/send?access_token=77da9016b0ea11e55e662d9a1775a30f314ffb79d18fa9e4ea6fd9a1a78d879e
    jira_login:
        jira_url: https://hs-cas.hundsun.com/cas/login?service=https%3A%2F%2Fse.hundsun.com%2Fsecure%2FDashboard.jspa
        password: bGlqa0AyMDIx
        username: lijk34925
    jsql: status in (NEW, Assigned, Reopened, Resolved) AND resolution in ("未解决(无法解决)", "未解决(不需解决)", "未解决(无法重现)", "解决(修复成功)", "解决(不是缺陷)", "解决(重复缺陷)") AND reporter in ({})
    '''
    res = loadYaml(sss)
    print("res: ", res)

